package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

/**
 * Author：汤小洋
 * Date：2022-11-24 16:42
 * Description：<描述>
 */
@Controller
public class LoginController {

    // @RequestMapping("/showLogin")
    // public ModelAndView showLogin(){
    //     ModelAndView mav = new ModelAndView();
    //     mav.setViewName("login");
    //     return mav;
    // }

    @RequestMapping("/login")
    public ModelAndView login(String username, String password, HttpSession session){
        ModelAndView mav = new ModelAndView();
        if ("admin".equals(username) && "123".equals(password)){
            // mav.addObject("username",username);
            mav.setViewName("success");

            session.setAttribute("username",username);
        }else{
            mav.addObject("errorMsg","用户名或密码不正确！");
            mav.setViewName("login");
        }
        return mav;
    }

}
